﻿namespace MDXStudio
{
    using Microsoft.AnalysisServices.AdomdClient;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using WeifenLuo.WinFormsUI.Docking;

    public class ResultsWindow : DockContent
    {
        private IContainer components;
        private System.Windows.Forms.DataGridView dataGridCellSet;
        internal MDXStudio.DebugWatch DebugWatch;
        private ToolStrip toolStrip1;
        private ToolStripButton toolStripButtonClear;
        private ToolStripContainer toolStripContainer1;
        private ToolStripDropDownButton toolStripDropDownButtonShowCellProp;
        internal MDXStudio.VirtualGrid VirtualGrid;

        public ResultsWindow()
        {
            this.InitializeComponent();
        }

        private void dataGridCellSet_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
        {
            try
            {
                this.VirtualGrid.CellValueNeeded(sender, e);
            }
            catch (Exception)
            {
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            DataGridViewCellStyle style2 = new DataGridViewCellStyle();
            DataGridViewCellStyle style3 = new DataGridViewCellStyle();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(ResultsWindow));
            this.dataGridCellSet = new System.Windows.Forms.DataGridView();
            this.toolStrip1 = new ToolStrip();
            this.toolStripButtonClear = new ToolStripButton();
            this.toolStripContainer1 = new ToolStripContainer();
            this.toolStripDropDownButtonShowCellProp = new ToolStripDropDownButton();
            ((ISupportInitialize) this.dataGridCellSet).BeginInit();
            this.toolStrip1.SuspendLayout();
            this.toolStripContainer1.ContentPanel.SuspendLayout();
            this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
            this.toolStripContainer1.SuspendLayout();
            base.SuspendLayout();
            this.dataGridCellSet.AllowUserToAddRows = false;
            this.dataGridCellSet.AllowUserToDeleteRows = false;
            this.dataGridCellSet.AllowUserToResizeColumns = false;
            this.dataGridCellSet.AllowUserToResizeRows = false;
            this.dataGridCellSet.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            this.dataGridCellSet.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
            this.dataGridCellSet.BackgroundColor = SystemColors.Window;
            this.dataGridCellSet.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
            style.Alignment = DataGridViewContentAlignment.MiddleLeft;
            style.BackColor = SystemColors.Control;
            style.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            style.ForeColor = SystemColors.WindowText;
            style.SelectionBackColor = SystemColors.Highlight;
            style.SelectionForeColor = SystemColors.HighlightText;
            style.WrapMode = DataGridViewTriState.True;
            this.dataGridCellSet.ColumnHeadersDefaultCellStyle = style;
            this.dataGridCellSet.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridCellSet.ColumnHeadersVisible = false;
            style2.Alignment = DataGridViewContentAlignment.MiddleLeft;
            style2.BackColor = SystemColors.Window;
            style2.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            style2.ForeColor = SystemColors.ControlText;
            style2.SelectionBackColor = SystemColors.Highlight;
            style2.SelectionForeColor = SystemColors.HighlightText;
            style2.WrapMode = DataGridViewTriState.False;
            this.dataGridCellSet.DefaultCellStyle = style2;
            this.dataGridCellSet.Dock = DockStyle.Fill;
            this.dataGridCellSet.Location = new Point(0, 0);
            this.dataGridCellSet.Name = "dataGridCellSet";
            this.dataGridCellSet.ReadOnly = true;
            this.dataGridCellSet.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
            style3.Alignment = DataGridViewContentAlignment.MiddleLeft;
            style3.BackColor = SystemColors.Control;
            style3.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            style3.ForeColor = SystemColors.WindowText;
            style3.SelectionBackColor = SystemColors.Highlight;
            style3.SelectionForeColor = SystemColors.HighlightText;
            style3.WrapMode = DataGridViewTriState.True;
            this.dataGridCellSet.RowHeadersDefaultCellStyle = style3;
            this.dataGridCellSet.RowHeadersVisible = false;
            this.dataGridCellSet.SelectionMode = DataGridViewSelectionMode.CellSelect;
            this.dataGridCellSet.Size = new Size(0x124, 0xf8);
            this.dataGridCellSet.TabIndex = 2;
            this.dataGridCellSet.VirtualMode = true;
            this.dataGridCellSet.CellValueNeeded += new DataGridViewCellValueEventHandler(this.dataGridCellSet_CellValueNeeded);
            this.toolStrip1.Dock = DockStyle.None;
            this.toolStrip1.Items.AddRange(new ToolStripItem[] { this.toolStripButtonClear, this.toolStripDropDownButtonShowCellProp });
            this.toolStrip1.Location = new Point(7, 0);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new Size(220, 0x19);
            this.toolStrip1.TabIndex = 3;
            this.toolStrip1.Text = "toolStrip1";
            this.toolStripButtonClear.Image = (Image) manager.GetObject("toolStripButtonClear.Image");
            this.toolStripButtonClear.ImageTransparentColor = Color.Magenta;
            this.toolStripButtonClear.Name = "toolStripButtonClear";
            this.toolStripButtonClear.Size = new Size(0x34, 0x16);
            this.toolStripButtonClear.Text = "Clear";
            this.toolStripButtonClear.TextDirection = ToolStripTextDirection.Horizontal;
            this.toolStripButtonClear.Click += new EventHandler(this.toolStripButtonClear_Click);
            this.toolStripContainer1.ContentPanel.Controls.Add(this.dataGridCellSet);
            this.toolStripContainer1.ContentPanel.Size = new Size(0x124, 0xf8);
            this.toolStripContainer1.Dock = DockStyle.Fill;
            this.toolStripContainer1.Location = new Point(0, 0);
            this.toolStripContainer1.Name = "toolStripContainer1";
            this.toolStripContainer1.Size = new Size(0x124, 0x111);
            this.toolStripContainer1.TabIndex = 4;
            this.toolStripContainer1.Text = "toolStripContainer1";
            this.toolStripContainer1.TopToolStripPanel.Controls.Add(this.toolStrip1);
            this.toolStripDropDownButtonShowCellProp.Image = (Image) manager.GetObject("toolStripDropDownButtonShowCellProp.Image");
            this.toolStripDropDownButtonShowCellProp.ImageTransparentColor = Color.Magenta;
            this.toolStripDropDownButtonShowCellProp.Name = "toolStripDropDownButtonShowCellProp";
            this.toolStripDropDownButtonShowCellProp.Size = new Size(0x7f, 0x16);
            this.toolStripDropDownButtonShowCellProp.Text = "Show Cell Property";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x124, 0x111);
            base.Controls.Add(this.toolStripContainer1);
            base.HideOnClose = true;
            base.Name = "ResultsWindow";
            base.TabText = "ResultsWindow";
            this.Text = "ResultsWindow";
            ((ISupportInitialize) this.dataGridCellSet).EndInit();
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.toolStripContainer1.ContentPanel.ResumeLayout(false);
            this.toolStripContainer1.TopToolStripPanel.ResumeLayout(false);
            this.toolStripContainer1.TopToolStripPanel.PerformLayout();
            this.toolStripContainer1.ResumeLayout(false);
            this.toolStripContainer1.PerformLayout();
            base.ResumeLayout(false);
        }

        internal void InitToobarMenus()
        {
            this.toolStripDropDownButtonShowCellProp.DropDownItems.Clear();
            OlapInfoPropertyCollection.Enumerator enumerator = this.VirtualGrid.CellSetBinding.OlapInfo.CellInfo.CellProperties.GetEnumerator();
            while (enumerator.MoveNext())
            {
                OlapInfoProperty current = enumerator.Current;
                ToolStripMenuItem item = new ToolStripMenuItem(current.Name);
                item.Click += new EventHandler(this.toolStripMenuShow_Click);
                this.toolStripDropDownButtonShowCellProp.DropDownItems.Add(item);
            }
        }

        private void toolStripButtonClear_Click(object sender, EventArgs e)
        {
            this.dataGridCellSet.Rows.Clear();
            this.dataGridCellSet.Columns.Clear();
            if (this.DebugWatch != null)
            {
                this.DebugWatch.Clear();
            }
        }

        private void toolStripMenuShow_Click(object sender, EventArgs e)
        {
            this.VirtualGrid.CellProperty = (sender as ToolStripMenuItem).Text;
            this.VirtualGrid.Redraw();
        }

        internal System.Windows.Forms.DataGridView DataGridView
        {
            get
            {
                return this.dataGridCellSet;
            }
        }
    }
}

